/******************************************************************
 *  MRRM's testbench - memory access unit                         *
 *                                                                *
 *  This file is part of the MRRM project                         *
 *  <http://mrrm.googlecode.com/>                                 *
 *                                                                *
 *  Author(s):                                                    *
 *    -  Wu Jinkai                                                *
 *                                                                *
 ******************************************************************
 *                                                                *
 *  Copyright (C) 2010 AUTHORS                                    *
 *                                                                *
 *  This source file may be used and distributed without          *
 *  restriction provided that this copyright statement is not     *
 *  removed from the file and that any derivative work contains   *
 *  the original copyright notice and the associated disclaimer.  *
 *                                                                *
 *  MRRM is free software: you can redistribute it and/or modify  *
 *  it under the terms of the GNU General Public License as       *
 *  published by the Free Software Foundation, either version 3   *
 *  of the License, or (at your option) any later version.        *
 *                                                                *
 *  MRRM is distributed in the hope that it will be useful, but   *
 *  WITHOUT ANY WARRANTY; without even the implied warranty of    *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  *
 *  GNU General Public License for more details.                  *
 *                                                                *
 *  You should have received a copy of the GNU General Public     *
 *  License along with MRRM. If not, see                          *
 *  <http://www.gnu.org/licenses/>.                               *
 *                                                                *
 ******************************************************************/

`include "global.v"

module mrrm_test_mem;
  
  parameter aw = `MEMORY_ADDR_WIDTH;
  parameter ow = `OPERAND_WIDTH;
  
  // Interfaces
  // Data memory
  wire [aw-1:0] dmemaddr;
  wire dmemwr;
  wire dmemrd;
  wire [ow-1:0] dmemdataw;
  reg [ow-1:0] dmemdatar;
  wire dmembyte;

  // MEM
  reg [2:1] M_itype;
  reg M_ifun_b;
  reg M_snl;
  reg [ow-1:0] M_valx;
  reg [ow-1:0] M_vale;
  wire [ow-1:0] m_valm;
  
mrrm_mem t_mrrm_mem(
	.dmemaddr(dmemaddr), .dmemwr(dmemwr), .dmemrd(dmemrd), 
	.dmemdataw(dmemdataw), .dmemdatar(dmemdatar), .dmembyte(dmembyte),
	.M_itype(M_itype), .M_ifun_b(M_ifun_b), .M_snl(M_snl), 
	.M_valx(M_valx), .M_vale(M_vale), .m_valm(m_valm)
	);
	
initial
  begin
    // Initial
    dmemdatar = 0;
    M_itype = 0; // `I_REG = 3'b000
    M_ifun_b = 0;
    M_snl = 0;
    M_valx = 0;
    M_vale = 0;
    
    // Get memory address
    #90 M_valx = 32'h00001234;
    // Store instruction
    #100 M_snl = 1'b0;
    M_itype = 2'b01;
    // Load instruction
    #100 M_snl = 1'b1;
    // Get data to memory
    #100 M_vale = 32'h12340000;
    // Memory access function
    #100 M_ifun_b = 1'b1;
    // Get data from memory
    #100 dmemdatar = 32'h10203040;    
    
  end
  
initial
  begin
    $monitor("Time@%d, dmemaddr=%h, dmemwr=%d, dmemrd=%d, dmemdataw=%h, dmembyte=%d, m_valm=%h",
      $time, dmemaddr, dmemwr, dmemrd, dmemdataw, dmembyte, m_valm
    );
  end
    
endmodule
